package com.event;

import com.mysqld.Mysqld;
import com.window.ChangeAccountInfo;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ChangeInfoEvent implements ActionListener {
    @Override
    public void actionPerformed(ActionEvent e) {
        char[] str = ChangeAccountInfo.passwordtext.getPassword();//获取密码
        String password = new String(str);
        if (ChangeAccountInfo.accounttext.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "账号不能为空", "更改页面", JOptionPane.WARNING_MESSAGE);
        } else if (ChangeAccountInfo.nametext.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "姓名不能为空!", "更改页面", JOptionPane.WARNING_MESSAGE);
        } else if (password.equals("")) {
            JOptionPane.showMessageDialog(null, "密码不能为空!", "更改页面", JOptionPane.WARNING_MESSAGE);
        } else {
            try {
                if (Mysqld.changeinfo(ChangeAccountInfo.accounttext.getText())) {
                    Mysqld.changeotheraccount();//改信息
                    JOptionPane.showMessageDialog(null, "更改成功!", "更改页面", JOptionPane.WARNING_MESSAGE);
                    ManageEvent.changeaccountinfo.dispose();//关闭修改信息界面
                } else {
                    JOptionPane.showMessageDialog(null, "账号不存在，更改失败!", "更改页面", JOptionPane.WARNING_MESSAGE);
                }
            } catch (Exception e1) {
            }
        }
    }
}
